'''
根据'匹配用'字段将产品总表中的'产品层级2'map进入净费规则表

'''

import os
import numpy as np
import pandas as pd

from utils_func.env import ROOT_PATH

if __name__ == '__main__':
    # # TODO
    # proj = '苏宁大陆'
    # insurer = '人保'
    # file = '新增产品净费3'
    # prod = pd.read_csv(f'{ROOT_PATH}\constant\产品总表new.csv')
    # prod_slice = prod[(prod['项目']==proj)&(prod['保司']==insurer)]
    # new_jingfei = pd.read_csv(f'{ROOT_PATH}\constant\{file}.csv')
    # res = new_jingfei.join(prod_slice[['统计品类','产品层级2','匹配用']].set_index('匹配用'),on='匹配用').dropna().reset_index(drop=True)

    # res.to_csv(f'{ROOT_PATH}\constant\净费规则表_{proj}{insurer}{file}.csv')

    # TODO
    proj = '苏宁香港'
    insurer = '人保'
    file = '净费规则表new'
    prod = pd.read_csv(f'{ROOT_PATH}\constant\产品总表new.csv')
    prod_slice = prod[(prod['项目']==proj)&(prod['保司']==insurer)]
    new_jingfei = pd.read_csv(f'{ROOT_PATH}\constant\{file}.csv',encoding='GBK',index_col=0)
    res = new_jingfei[(new_jingfei['项目']==proj)&(new_jingfei['保司']==insurer)].join(prod_slice[['统计品类','匹配用']].set_index('匹配用'),on='匹配用').dropna(how='all').reset_index(drop=True)

    res.to_excel(f'{ROOT_PATH}\constant\净费规则表_{proj}{insurer}.xlsx',index=False)